<?
    require_once("mvc/action/ActionForm.php");
    require_once("mvc/action/ActionMessage.php");
    require_once("mvc/action/ActionMessages.php");

    require_once("cms/forum/om/Topic.php");


    class BaseTopicForm extends ActionForm {

        protected $topic;

        public function __construct() {
            $this->topic = new Topic();
        }

        public function getTopic() {
            return $this->topic;
        }

        public function setTopic(Topic $topic) {
            $this->topic = $topic;
        }

        public function validate() {

            $errors = new ActionMessages();

            if(is_null($this->getTopic()->getName()) || strlen($this->getTopic()->getName()) == 0)
                $errors->add("topic->name",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.name", true)));


            if(!is_null($this->getTopic()->getName()) && strlen($this->getTopic()->getName()) > 0 && strlen($this->getTopic()->getName()) > 255)
                $errors->add("topic->name",
                    new ActionMessage("errors.maxlength", true, array(
                        new ActionMessage("prompt.name", true),
                        new ActionMessage("255", false))));


            if(is_null($this->getTopic()->getBody()) || strlen($this->getTopic()->getBody()) == 0)
                $errors->add("topic->body",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.body", true)));


            return $errors;
        }

    }
?>